package com.binary.file.device;

import java.io.DataInput;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class DataTest {

	public static void main(String[] args) throws Exception {
		String path = "D:" + File.separator;
		String fileName = "44030000_0005_20170613_103653_0.0_4.2E9_25kHz_H_M.bin";
		readBinData(path, fileName);

	}

	private static void readBinData(String path, String fileName)
			throws FileNotFoundException, IOException, Exception {
		// 挨个读取
		RandomAccessFile in = new RandomAccessFile(path + fileName, "r");
		// System.out.println(in.readShort());
		// System.out.println(in.readByte());
		// System.out.println(in.readShort());
		// System.out.println(in.readByte());
		// System.out.println(in.readByte());
		// System.out.println(in.readByte());
		// System.out.println(in.readByte());
		// System.out.println(in.readByte());

		int len = (int) (in.length() / RecordDataEntity.RecordSize);
		for (long i = 0; i < len; i++) {
			in.seek(i * RecordDataEntity.RecordSize);
			RecordDataEntity emp = readEmp(in);
			System.out.println(emp.toString());
		}
	}

	/**
	 * 读取数据
	 * @param in
	 * @return
	 * @throws Exception
	 */
	private static RecordDataEntity readEmp(DataInput in) throws Exception {
		RecordDataEntity entity = new RecordDataEntity();
		entity.setCarCode(in.readShort());
		entity.setDeviceInfo(in.readByte());
		entity.setYear(in.readShort());
		entity.setMouth(in.readByte());
		entity.setDay(in.readByte());
		entity.setHour(in.readByte());
		entity.setMinute(in.readByte());
		entity.setSecond(in.readByte());
		entity.setMiniSecond(in.readShort());
		entity.setLongitude(in.readDouble());
		entity.setLatitude(in.readDouble());
		entity.setHeight(in.readInt());
		entity.setBeginHz(in.readLong());
		entity.setStep(in.readInt());
		entity.setHzPoint(in.readInt());
		double[] testData = new double[1023];
		for (int i = 0; i < 1023; i++) {
			testData[i] = in.readDouble();
		}
		entity.setTestData(testData);
		return entity;
	}

}
